﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Domain.ViewModels.BasicSet.Manufacturer;
using WaterRevenueMS.Componnent.Common;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(IManufacturerService))]
    public class ManufacturerService : CoreServiceBase, IManufacturerService
    {
        [Import]
        public IManufacturerRepository ManufacturerRepository { get; set; }

        public IQueryable<Manufacturer> Manufacturers
        {
            get { return ManufacturerRepository.Entities; }
        }
        public OperationResult Insert(ManufacturerModel model)
        {
            var entity = new Manufacturer
            {
                Shui_BCS=model.Shui_BCS,
                DefaultValue=0,
                CreateDT=DateTime.Now,
                ReviseDT=DateTime.Now,
                OrderNo=model.OrderNo,
                Chang_SMC=model.Chang_SMC,
                Chang_SJJ=model.Chang_SJJ,
                Chang_SDZ=model.Chang_SDZ,
                Dian_H=model.Dian_H,
                Chuan_Z=model.Chuan_Z,
                Lian_XR=model.Lian_XR
            };
            ManufacturerRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(ManufacturerModel model)
        {
            var entity = ManufacturerRepository.Entities.FirstOrDefault(t => t.Id == model.Id);
            entity.Shui_BCS = model.Shui_BCS;
            entity.ReviseDT = DateTime.Now;
            entity.OrderNo = model.OrderNo;
            entity.Chang_SMC = model.Chang_SMC;
            entity.Chang_SJJ = model.Chang_SJJ;
            entity.Chang_SDZ = model.Chang_SDZ;
            entity.Dian_H = model.Dian_H;
            entity.Chuan_Z = model.Chuan_Z;
            entity.Lian_XR = model.Lian_XR;
            ManufacturerRepository.Update(entity);
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public Componnent.Common.OperationResult Delete(int Id)
        {
            var entity = ManufacturerRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                ManufacturerRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
